package com.example.actionbardemo;

import com.example.actionbardemo.fragment.BaseFragment;
import android.app.ActionBar;
import android.app.ActionBar.OnNavigationListener;
import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.SpinnerAdapter;

public class PullDownNavActivity extends FuncListActivity {
	private ActionBar actionBar;
	private OnNavigationListener mOnNavigationListener;
	/**导航列表标题*/
	private String[] items;
	
	@Override
	public int getContentViewID() {
		return R.layout.activity_pulldown_nav;
	}
	
	@Override
	public boolean isBackIconVisible() {
		return true;
	}
	
	@Override
	public void initData() {
		items = getResources().getStringArray(R.array.nav_list);
	}
	
	@Override
	public void initView() {
		//初始化一个SpinnerAdapter 
//		SpinnerAdapter mSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.nav_list, android.R.layout.simple_spinner_dropdown_item); 
		SpinnerAdapter mSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.nav_list, R.layout.simple_spinner_dropdown_item); 
		
		actionBar = getActionBar();  
		actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);//导航模式必须设为NAVIGATION_MODE_LIST  
		//生成一个OnNavigationListener来响应ActionBar的菜单项点击操作
		mOnNavigationListener = new OnNavigationListener() {
			@Override
			public boolean onNavigationItemSelected(int itemPosition, long itemId) {
				String content = items[itemPosition];  
	            BaseFragment newFragment = new BaseFragment(content);
	            getSupportFragmentManager().beginTransaction().replace(R.id.fl_content, newFragment).commit();
	            return true;  
			}
		};
		actionBar.setListNavigationCallbacks(mSpinnerAdapter,mOnNavigationListener);  
	}
}
